package cn.chenxhcloud.myvv;

import java.nio.ByteBuffer;

import org.voovan.network.IoHandler;
import org.voovan.network.IoSession;
import org.voovan.network.exception.SocketDisconnectByRemote;
import org.voovan.tools.log.Logger;

@SuppressWarnings("all")
public class ServerHandler implements IoHandler {

    public Object onConnect(IoSession session) {
        Logger.simple("onConnect");
        return null;
    }

    public void onDisconnect(IoSession session) {
        Logger.simple("onDisconnect");
    }

    public Object onReceive(IoSession session, Object obj) {
        Logger.simple("Server onRecive: "+obj.toString());
        return "===="+obj.toString().trim()+" ===== \r\n";
    }

    public void onException(IoSession session, Exception e) {
        if(e instanceof SocketDisconnectByRemote){
            Logger.simple("Connection disconnect by client");
        }else {
            Logger.error("Server Exception:",e);
        }
        session.close();
    }

    public void onSent(IoSession session, Object obj) {
        ByteBuffer sad = (ByteBuffer)obj;
        sad = (ByteBuffer)sad.rewind();
        Logger.simple("Server onSent: "+new String(sad.array()));
    }

	public void onIdle(IoSession arg0) {
		// TODO Auto-generated method stub
		
	}

}
